/////////////////////////////////////////////////////////////////////////////////////////////		
* This do-file generates TABLE A.2 & TABLE 3												*
/////////////////////////////////////////////////////////////////////////////////////////////	

use "${inputdir}/prospects_analysis_dataset_clean.dta", clear

local controls1 = "female reg_age age2 i.r1_HighGrade i.reg_commid"
local controls0 = "female reg_age age2 r1_HighGrade"
local ps1 =	"r1_welfare_today_std r1_selfesteem_std r1_locuscontrol_std r1_aggression_std r1_riskybehavior_std" 	

* BASELINE CORRELATIONS

	keep `controls0' hrsworked_trim* inc7d_ihst* lfi* ANYSFC sfc_any respid female reg_commid `ps1'  
		
	reshape long hrsworked_trim inc7d_ihst lfi, i(respid) j(time)

	egen temp = rowtotal(r1_welfare_today_std r1_selfesteem_std r1_locuscontrol_std r1_aggression_std r1_riskybehavior_std)
	keep if time==1
	sum temp, detail
	gen psi_bl = (temp - r(mean)) / r(sd)
	
	local k = 1	
	foreach oc in hrsworked_trim inc7d_ihst lfi{
	
		reg `oc' `ps1' i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo r`k'
	
		reg `oc' psi_bl i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo s`k'			
				
		reg `oc' r1_welfare_today_std i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo a`k'			
		
		reg `oc' r1_selfesteem_std i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo b`k'		
		
		reg `oc' r1_locuscontrol_std i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo c`k'		
		
		reg `oc' r1_aggression_std i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo d`k'		
		
		reg `oc' r1_riskybehavior_std i.reg_commid `controls1' , robust	
		estadd loc covs = "No"
		estadd ysumm
		eststo e`k'				
						
		local k = `k' + 1
		}
				
				* APPENDIX TABLE A2
				# delimit ;
					esttab r1 r2 r3 using "${outputdir}/tables/Table_A2.tex", replace b(%10.3f) se(%10.3f) scalars(
					"ymean Mean Y" "N Individuals" "r2 R2")	sfmt(%10.2f %10.0f %10.3f) star(* 0.10 ** 0.05 *** 0.01) keep(`ps1') 
					order(`ps1')  varlabel(r1_locuscontrol_std "Locus of Control Index (LOC)" r1_aggression_std "Aggressive Behaviors Index (Agro)" r1_selfesteem_std "Self-Esteem Index (SE)" r1_riskybehavior_std "Risky Behaviors Index (RB)" r1_welfare_today_std "Welfare Today (WF)" psi_std "PSI"  ) 
					mlabels("Hours" "IHST(7dI)" "LFI")
					align(cccccccccccc) addnotes("Earnings and hours trim top 1\%." "Covars: `controls1'" "LFI=Labor Force Index" "All variables coded so that positive is better") title(Labor Outcomes and Jointly Estimated Psychosocial Associations);
				# delimit cr	
	
				* TABLE 3				
				# delimit ;
					esttab a3 b3 c3 d3 e3 s3 using "${outputdir}/tables/Table_3.tex", replace b(%10.3f) se(%10.3f) scalars(
					"ymean Mean Y" "N Individuals" "r2 R2")	sfmt(%10.2f %10.0f %10.3f) star(* 0.10 ** 0.05 *** 0.01) keep(`ps1' psi*) 
					order(`ps1' psi*)  varlabel(r1_locuscontrol_std "Locus of Control Index (LOC)" r1_aggression_std "Aggressive Behaviors Index (Agro)" r1_selfesteem_std "Self-Esteem Index (SE)" r1_riskybehavior_std "Risky Behaviors Index (RB)" r1_welfare_today_std "Welfare Today (WF)" psi_bl "Psychosocial Index (PSI)"  ) 
					mlabels(LFI LFI LFI LFI LFI LFI)
					align(cccccccccccc) addnotes("Earnings and hours trim top 1\%." "Covars: `controls1'" "LFI=Labor Force Index" "All variables coded so that positive is better") title(Baseline Labor Force Index (LFI) Correlations with Psychosocial Measures);
				# delimit cr					
